	
function decimalPoint(price,digit){
		if(digit == null||digit==''){
			digit = 2;
		}
		return (parseFloat(price)+0.00).toFixed(digit)
} 

function selectUseRule(goodTotalPrice, rules){
    if(rules!=null && rules.length>0) {
        var fristRule = rules[0];
        var lastRule = rules[rules.length - 1];
        if (goodTotalPrice < fristRule.money) {
            return null;
        } else if (goodTotalPrice>= lastRule.money) {
            return lastRule;
        } else {
            var ruleIndex = 0;
            for (var i = 0; i < rules.length; i++) {
                var currRuleVO = rules[i];
                if (goodTotalPrice <currRuleVO.money) {
                    ruleIndex = i - 1;
                    break;
                }
            }
            return rules[ruleIndex];
        }
    }
    return null;
}

	

function  getDisInfoForDerate( ruleInfo, goodTotalPrice){
    var discountInfo = new Object();
    if(ruleInfo!=null){
        var derateMoney = ruleInfo.derateMoney;
        var currFavMoney =FloatSub(goodTotalPrice,derateMoney) ;
        discountInfo.ruleInfo=ruleInfo;
        discountInfo.goodFavMoney=currFavMoney;
        discountInfo.goodDisMoney=derateMoney;
    }

    return discountInfo;
}


function  getDisInfoForDiscount( ruleInfo, goodTotalPrice){
    var discountInfo = new Object();
    if(ruleInfo!=null){
        var discount =1- ruleInfo.discount/10;
        var tmpMoney =Math.round( FloatMul(goodTotalPrice,discount)*100)/100;
        var currFavMoney =FloatSub (goodTotalPrice,tmpMoney);
        discountInfo.ruleInfo=ruleInfo;
        discountInfo.goodFavMoney=currFavMoney;
        discountInfo.goodDisMoney=FloatSub(goodTotalPrice,currFavMoney);
    }

    return discountInfo;
}


	function FloatAdd(arg1,arg2){
		    var r1,r2,m,n;
		    try{r1=arg1.toString().split(".")[1].length}catch(e){r1=0}
		    try{r2=arg2.toString().split(".")[1].length}catch(e){r2=0}
		    m=Math.pow(10,Math.max(r1,r2));
		    n=(r1>=r2)?r1:r2;
		    var decimalPointValue = ((arg1*m+arg2*m)/m).toFixed(n)
		    return decimalPoint(decimalPointValue);
		}


    function FloatSub(arg1,arg2){
		    var r1,r2,m,n;
		    try{r1=arg1.toString().split(".")[1].length}catch(e){r1=0}
		    try{r2=arg2.toString().split(".")[1].length}catch(e){r2=0}
		    m=Math.pow(10,Math.max(r1,r2));
		    n=(r1>=r2)?r1:r2;
		    var decimalPointValue = ((arg1*m-arg2*m)/m).toFixed(n);
		    return decimalPoint(decimalPointValue);
		}

	function FloatMul(arg1,arg2){
		    var m=0,s1=arg1.toString(),s2=arg2.toString();
		    try{m+=s1.split(".")[1].length}catch(e){}
		    try{m+=s2.split(".")[1].length}catch(e){}
		   var decimalPointValue =  (Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m));
		   return decimalPoint(decimalPointValue);
		}

	function FloatDiv(arg1,arg2){
		    var t1=0,t2=0,r1,r2;
		    try{t1=arg1.toString().split(".")[1].length}catch(e){}
		    try{t2=arg2.toString().split(".")[1].length}catch(e){}
		    with(Math){
		        r1=Number(arg1.toString().replace(".",""))
		        r2=Number(arg2.toString().replace(".",""))
		        
		        var decimalPointValue = (r1/r2)*pow(10,t2-t1);
		        return decimalPoint(decimalPointValue);
		    }
		}

	